﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace OperaHouse.Configuration
{
    internal static class ConfigurationHelper
    {
        public static string GetString(string key)
        {
            string appSetting = ConfigurationManager.AppSettings[key];

            if (appSetting == null)
            {
                throw new ArgumentException(string.Format("Configuration key {0} is missing.", key));
            }

            return appSetting;
        }

        public static int GetInt32(string key)
        {
            string appSetting = GetString(key);
            return int.Parse(appSetting);
        }

        public static bool GetBool(string key)
        {
            string appSetting = GetString(key);
            return bool.Parse(appSetting);
        }

        public static TimeSpan GetTimeSpan(string key)
        {
            string[] timeSpanParts = GetString(key).Split(':');
            TimeSpan timeSpan = new TimeSpan(int.Parse(timeSpanParts[0]),
                int.Parse(timeSpanParts[1]),
                int.Parse(timeSpanParts[2]));

            return timeSpan;
        }

    }
}
